package com.fow.core.platform.web.rest;

import com.fow.core.platform.exception.ResourceNotFoundException;
import com.fow.core.platform.web.rest.exception.ExceptionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;

/**
 * Created by Greg.Chen on 2015/5/7.
 */
public class PageController {
    private static final Logger logger = LoggerFactory.getLogger(PageController.class);


    @ExceptionHandler(ResourceNotFoundException.class)
    @ResponseStatus(HttpStatus.NOT_FOUND)
    public String handleResourceNotFoundException() {
        return "page404";
    }

    @ExceptionHandler(value = Throwable.class)
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public String error(Throwable e) {
        String errorMessage = ExceptionUtils.stackTrace(e);
        logger.error(errorMessage);
        return "page500";
    }
}
